﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Text;
using Yu.Cms.Common;

namespace Yu.Cms.Web.UserCtrl.Default
{
    public partial class Rss : BaseCtrl
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            StringBuilder code = new StringBuilder();

            code.Append("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n");
            code.Append("<rss version=\"2.0\">\n");
            code.Append("<channel>\n");
            code.AppendFormat("<title>{0}</title> \n", Utils.HtmlEncode(siteModel.SiteName));
            code.Append("<link>http://" + Request.ServerVariables["SERVER_NAME"] + "</link> \n");
            code.AppendFormat("<copyright>![CDATA[{0}]]</copyright> \n",Utils.HtmlEncode(siteModel.SiteCopyright));            
            IList<Yu.Cms.Model.Content> fam = bllContent.GetNewList(10);
            for (int i = 0; i < fam.Count; i++)
            {
                code.Append("<item>\n");
                code.AppendFormat("<title><![CDATA[{0}]]></title>\n", fam[i].Title);
                code.AppendFormat("<author>{0}</author> \n", Utils.HtmlEncode(siteModel.SiteEmail));
                code.AppendFormat("<link>/Article.aspx?PostID={0}</link>\n", fam[i].PostID);
                code.AppendFormat("<description><![CDATA[{0}]]></description>\n", Yu.Cms.Common.Utils.GetSubString(fam[i].aContent, 5000, "…"));
                code.AppendFormat("<subject>![CDATA[{0}]]</subject>\n", fam[i].Title);
                code.AppendFormat("<PubDate>{0}</PubDate>\n", fam[i].PubTime);
                code.AppendFormat("<category>{0}</category>\n",GetBigTypeNameByID (fam[i].BigTypeID));
                code.AppendFormat("<category>{0}</category>\n", GetSmallTypeNameByID(fam[i].SmallTypeID));
                code.AppendFormat("<comments>/Article.aspx?PostID={0}#respond</comments>", fam[i].PostID);
                code.Append("<comments>0</comments>");
                code.AppendFormat("<copyright>![CDATA[{0}]]</copyright> \n", Utils.HtmlEncode(siteModel.SiteCopyright));
                code.Append("</item>\n");
            }
            code.Append("</channel>\n");
            code.Append("</rss>\n");
            Response.ContentType = "text/xml";
            Response.Write(code);

        }
    }
}